/*
	The MIT License

	Copyright (c) 2010 IFMO/GameDev Studio

	Permission is hereby granted, free of charge, to any person obtaining a copy
	of this software and associated documentation files (the "Software"), to deal
	in the Software without restriction, including without limitation the rights
	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
	copies of the Software, and to permit persons to whom the Software is
	furnished to do so, subject to the following conditions:

	The above copyright notice and this permission notice shall be included in
	all copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
	THE SOFTWARE.
*/

#pragma once

/*-----------------------------------------------------------------------------
	String :
-----------------------------------------------------------------------------*/

#include "va.h"
#include "args.h"


CORE_API void	common_parti( char *s, const char *sample );
CORE_API EQuaternion	atoq		( const char *str );
CORE_API EColor			atoc		( const char *str );
CORE_API EVector		atov		( const char *str );

CORE_API bool	streq		( const char *a, const char *b );

CORE_API unsigned int	StupidHash(const char *str);
CORE_API unsigned int	RSHash(const char *str);
CORE_API unsigned int	JSHash(const char* str);

CORE_API bool	WildMatch	( const char *filter, const char *str );
CORE_API bool	MatchFilter	( const char *filter, const char *name );
CORE_API bool	IsAlpha		( char ch );
CORE_API bool	IsDigit		( char ch );

CORE_API string	TrimString	( const string &s );
CORE_API string	DecolorizeString( const string &str );
CORE_API string	RemoveExtension( const string &path );
CORE_API string	ExtractDirectory( const string &path );

	
	
class CORE_API EString  {
	public:
		//	NPOS = -1, (its important for some reason!)
		static const uint	NPOS	=	(uint)(-1);

	public:		
						EString			( void );
						EString			( const char *str );
						EString			( const char *str, uint begin, uint end );
						EString			( const EString &other );
						~EString		( void );
		EString			&operator =		( const EString &other );
		EString			&operator =		( const char *str );
		bool			operator ==		( const EString &other ) const;
		bool			operator !=		( const EString &other ) const;
		char			operator []		( uint index ) const;
		const char		*CStr			( void ) const; 
		
		CORE_API friend EString	operator +	( const EString &a, const EString &b );
		EString	&		operator +=		( const EString &other );

		uint			Length			( void ) const;		
		EString			Substr			( uint begin, uint end ) const;
		uint			Find			( char ch, uint begin=0, uint end=NPOS ) const;
		uint			RFind			( char ch, uint begin=0, uint end=NPOS ) const;
		
		EString			GetFileName			( void ) const;
		EString			GetFileExtension	( void ) const;
		
	private:
		uint		atom;
		const char *string;
	};
	
